package com.cuanbobox.utils;

import com.cuanbobox.base.App;
import com.cuanbobox.bean.DataBean;
import com.cuanbobox.bean.DataList;
import com.cuanbobox.constant.MatrixConstant;

import java.util.List;

/**
 * 设备状态工具类
 */
public class DevStateUtil {

    /**
     * 批量保存
     *
     * @param cmdList 指令集合
     */
    public static void batchSave(List<String> cmdList) {
        if (cmdList == null) return;
        for (int i = 0; i < cmdList.size(); i++) {
            String cmd = cmdList.get(i);
            save(cmd);
        }
    }

    /**
     * 保存设备状态
     *
     * @param cmd 指令名称
     */
    public static void save(String cmd) {
        if (cmd.contains("开") || cmd.contains("关")) {
            String key = cmd.replace("开", "").replace("关", "");
            //保存设备状态
            SharedPreferencesUtil.save(App.getInstance(), key, cmd);
        } else if (cmd.equals("锐取VGA") || cmd.equals("锐取多画面785")) {
            SharedPreferencesUtil.save(App.getInstance(), "锐取录像", cmd);
        }
    }

    /**
     * 批量改变设备状态（不执行指令）
     *
     * @param cmdList 指令集合
     */
    public static void batchChangeDevState(List<String> cmdList) {
        if (cmdList == null || cmdList.size() == 0) return;
        for (int i = 0; i < cmdList.size(); i++) {
            String cmdStr = cmdList.get(i);
            BroadcastUtil.sendMatrixBroadcast(MatrixConstant.TYPE_MATRIX_RECEIVE_MSG, "<APPS-START:" + cmdStr + ",1.");
        }
    }

}
